import Vue from 'vue';
import Router from 'vue-router';
import Loading from '@/components/Loading';//加载页面1
import Home from '@/components/Home';//首页2
import Video from '@/components/Video';//视频页3
import Intro from '@/components/Intro';//CEO列表页面
import Agreements from '@/components/Agreements';//志愿者协议
import VolunteerForm from '@/components/VolunteerForm';//志愿者表单
import AssitorForm from '@/components/AssitorForm';//助力者表单
import About from '@/components/About';//关于4
import Auth from '@/components/Auth'
import Poster from '@/components/Poster'
import  TicketAgreement from  '@/components/TicketAgreement'
import store from '@/store'

import ConfidentialityAgreement from '@/components/ConfidentialityAgreement'//保密协议

Vue.use(Router)

const router = new Router({
  mode:'hash',
  routes: [
    {
      path: '/',
      name: 'Loading',
      component: Loading
    },{
      path:'/auth',
      name:'auth',
      component:Auth
    },{
          path:'/ticketAgreement',
          name:'ticketAgreement',
          component:TicketAgreement
      },{
      path: '/home',
      name: 'home',
      component: Home
    },{
      path:'/video',
      name:'video',
      component: Video
    },{
      path:'/intro',
      name:'intro',
      component: Intro
    },{
      path:'/agreements',
      name:'agreements',
      component: Agreements
    },{
      path:'/volunteerForm',
      name:'volunteerForm',
      component: VolunteerForm
    },{
      path:'/assitorForm',
      name:'assitorForm',
      component: AssitorForm
    },{
      path:'/about',
      name:'about',
      component: About
    },{
      path:'/poster',
      name:'poster',
      component: Poster
    }
  ]
})

/**
* 进入路由之前
* **/
router.beforeEach((to, from, next) => {
  if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') {
    window.entryUrl = location.href.split('#')[0];
  }
  next()
  // location.href="http://zhiyang.yizehd.com/api/auth/auth?state=1&uri=http://zhiyang.yizehd.com/zhuli&mum="+Math.random();

  // next()
  // const token = window.localStorage.getItem('user_token')
  // if (token) {
  //   if (to.path === '/auth') {
  //     next({
  //       path: '/'
  //     })
  //   } else {
  //     store
  //       .dispatch('fishH5/getUserInfoFn', {
  //         user_token: token
  //       })
  //       .then(res => {
  //         // 拉取用户信息
  //         next()
  //       })
  //   }
  // } else {
  //   if (to.path !== '/auth') {
  //     // 保存用户进入的url
  //     if (to.path === '/loading' || to.path === '/home') {
  //       window.localStorage.setItem('authUrl', to.fullPath) // 保存用户进入的url
  //     }
  //     window.location.href = 'http://zhiyang.yizehd.com/api/auth/auth?state=1&uri=http://zhiyang.yizehd.com/zhuli'
  //   } else {
  //     next()
  //   }
  // }


});
router.afterEach(()=>{
})
export default router;
